<template>
    <!-- <ListPageFrame page-title="分类" @scrolltolower="doSearch(false)"> -->
    <Tabs @changeTabs="changeTabs" :list="list" :current="currentTab"></Tabs>

    <view class="my-wish">
        <ListContent :list="cards" keyof="id">
            <template #default="{ item, index }">
                <InfoCard position="wish" :data="item" :key="item.id">
                </InfoCard>
            </template>
        </ListContent>
        <view class="push" @click="toPush">
            <img style="width: 150rpx;height: 150rpx;" src="@/assets/images/push-btn.png" alt="">
        </view>
    </view>
</template>
<script lang="ts" setup>
import { onMounted, reactive, ref, onUnmounted } from 'vue';
import ListContent from '@/components/ListContent/ListContent.vue'
import Tabs from '@/components/Tabs/Tabs.vue'
import InfoCard from '@/components/InfoCard/InfoCard.vue'
import { onPullDownRefresh } from '@dcloudio/uni-app';
import api from '@/apis/api';

let list = ref([
    {
        id: -1, name: '全部'
    },
    {
        id: 0, name: '无效'
    },
    {
        id: 1, name: '审核中'
    },
    {
        id: 2, name: '有效中'
    },
    {
        id: 3, name: '已完成'
    }
]);
let cards = ref([])
let currentTab = ref(-1)

onPullDownRefresh(() => {
    getMyWishByStatus().finally(() => {
        uni.stopPullDownRefresh()
    })
})

function getMyWishByStatus() {
    return api.getWishByStatus(currentTab.value == -1 ? '' : currentTab.value).then(({ data }) => {
        cards.value = data
    })
}

function changeTabs(index: number) {
    currentTab.value = index
    getMyWishByStatus()
}
function toPush() {
    uni.reLaunch({
        url: '/pages/push/push'
    })
}
onMounted(async () => {
    getMyWishByStatus()
})


</script>

<style lang="scss" scoped>
page {
    background: #f8f8f8;
}

.my-wish {
    padding: 0 30rpx;
    position: relative;

    .push {
        position: fixed;
        right: 30rpx;
        top: 70%;
    }
}
</style>